package org.example.types.exception;

import lombok.extern.slf4j.Slf4j;
import org.example.types.common.ResponseCode;
import org.example.types.model.Response;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author lxc18
 * @date 2025/4/8 14:56
 * @description GlobalExceptionHandler
 */
@Slf4j // Lombok 注解
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RateLimitExceededException.class)
    public Response<?> handleRateLimitExceeded(RateLimitExceededException ex) {
        log.warn("[RateLimit] 触发限流，{}秒不能超过{}次", ex.getWindowSize(), ex.getLimit());
        return Response.builder()
                .code(ResponseCode.RATE_LIMIT_EXCEEDED.getCode())
                .info(ResponseCode.RATE_LIMIT_EXCEEDED.getInfo())
                .data(null)
                .build();
    }
}
